import { api } from '../boot/axios';

function url(s: string) {
  return ['/api/tasks', s.replace('/', ''), ''].join('/');
}

export function createTask(
  task: string,
  description: string,
  cur_tab: boolean,
  final_tab: boolean,
  mtce_type: string,
  wi_no:string
) {
  return api({
    url: '/api/tasks/',
    method: 'post',
    data: {
      task,
      description,
      cur_tab,
      final_tab,
      mtce_type,
      wi_no
    },
  });
}

export function getTasks() {
  return api({
    url: '/api/tasks/',
    method: 'get',
  });
}

export function getCurTask(id: number) {
  return api({
    url: url(`${id}`),
    method: 'get',
  });
}

export function editCurTask(
  id: number,
  task: string,
  description: string,
  cur_tab: boolean,
  final_tab: boolean,
  mtce_type: string,
  wi_no:string
) {
  return api({
    url: url(`${id}`),
    method: 'patch',
    data: {
      task,
      description,
      cur_tab,
      final_tab,
      mtce_type,
      wi_no
    },
  });
}

export function deleteMasterTask(id: number) {
  return api({
    url: url(`${id}`),
    method: 'DELETE',
  });
}

export function softDeleteMasterTask(id: number) {
  return api({
    url: url('soft_delete_MasterTask'),
    method: 'DELETE',
    data:{
      id
    }
  })
}

export function getTaskByType(mtce_type: string) {
  return api({
    url: url('get_task_by_type'),
    method: 'post',
    data:{
      mtce_type
    }
  });
}

/**
 * 添加用户
 * @param mtce_type 
 * @returns 
 */
export function addTaskUser(data:{
  repair_order_task_id: number;
  check_user_id: number,
  flow: string
}) {
  let { repair_order_task_id, check_user_id, flow } = data;
  return api({
    url: '/api/repairordertasks/upldate_repair_order_task_check_user/',
    method: 'post',
    data:{
      repair_order_task_id,
      check_user_id,
      flow
    }
  });
}